package cn.ht.countDownLatchAndCyclicBarrierDemo;

/**
 * 功能描述 - 枚举使用演示
 * @author ht
 * @date 2020-5-21
 */
public enum peopleEnum {

    ONE(1,"关羽"),
    TWO(2,"张飞"),
    THREE(3,"赵云"),
    FOUR(4,"黄忠"),
    FIVE(5,"马超"),
    SIX(6,"吕布"),
    SEVEN(7,"孙策");

    /**
     * 功能描述 - 根据外部Code返回对应的对象
     * @author ht
     * @date 2020-5-21
     * @param index
     * @return cn.ht.countdownlatchdemo.peopleEnum
     */
    public static peopleEnum getPeople(Integer index){
        peopleEnum[] values = peopleEnum.values();
        for (peopleEnum value : values) {
            if(value.getCode().equals(index)){
                return value;
            }
        }
        return null;
    }

    private Integer code;
    private String message;

    peopleEnum() {
    }

    peopleEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
